package com.palrevo.data.services;

import com.palrevo.data.dao.DAO;
import com.palrevo.data.dao.DAOFactory;
import com.palrevo.data.dao.DaoRecord;
import com.palrevo.data.dao.DataException;

/**
 * 
 * @author AAsha
 *
 */
public abstract class ServiceBase {
	
	protected static final String LAST_ID_SQL = "SELECT LAST_INSERT_ID()";
	
	public enum Tables{
		users,pages, advertisements, adver_attachments, menu_items, programs, 
		lookup_cities, lookup_countries, programs_schedule, about_us;
	}
	
	public enum Columns{
		ID, USERNAME, TITLE, BODY, PASSWORD, TYPE, NAME, INDX, ICON, SMALLICON, PDF, ADVR_ID, PAGE_ID,
		INDEX, IS_LEAF, PARENT_ID, START_DATE, END_DATE, PROGRAM_ID, PROGRAM_NAME, CITY_ID, CITY_NAME;
	}
	
	/**
	 * 
	 * @return the id of the last inserted record id or -1 if not found.
	 * @throws DataException
	 */
	protected Object getLastInsertedRecordId() throws DataException{
		
		DAO dao = DAOFactory.getInstance().createDao();
		
		//Get Newly added record Id
		dao.execute(LAST_ID_SQL);
		DaoRecord record = dao.getResult().get(0);
		Object obj = record.getValue(0);
		if(obj == null){
			return -1;
		}
		
		return obj;
	}

}
